//
//  InfoTitlesViewController.m
//  OA
//
//  Created by apple on 15-11-19.
//  Copyright (c) 2015年 net. All rights reserved.
//

#import "InfoTitlesViewController.h"
#import "AppDelegate.h"
#import "Constants.h"
#import "InfoTemplate1.h"
#import "InfoTemplate2.h"
@implementation InfoTitlesViewController

NSMutableArray * InfoTitles;
AppDelegate * appDelegate;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title=@"信息标题";
    self.table.dataSource= self;
    self.table.delegate = self;
    InfoTitles = [[NSMutableArray alloc] init];
    appDelegate = [UIApplication sharedApplication].delegate;
    NSDictionary * params = @{@"sortId":self.twoDirId};
    // NSLog(@"%d",[self.twoDirId intValue]);
    [appDelegate.manager
     GET:url5
     parameters:params
     success:^(AFHTTPRequestOperation *operation, id responseObject) {
         //oneDirs = responseObject;
         [InfoTitles addObjectsFromArray:responseObject];
         //NSLog(@"%d",[oneDirs count]);
         [self.table reloadData];
     } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
         NSLog(@"获取服务器响应出错！");
     }];
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return InfoTitles.count;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell;
    if([self.module intValue]==1){
        cell = [tableView dequeueReusableCellWithIdentifier:@"template1" forIndexPath:indexPath];
        cell.layer.cornerRadius=12;
        cell.layer.masksToBounds=YES;
        UILabel * label = (UILabel*)[cell viewWithTag:1];
        label.text = [[InfoTitles objectAtIndex:indexPath.row] objectForKey:@"title"];
    }else{
        cell = [tableView dequeueReusableCellWithIdentifier:@"template2" forIndexPath:indexPath];
        cell.layer.cornerRadius=12;
        cell.layer.masksToBounds=YES;
        UILabel * label = (UILabel*)[cell viewWithTag:1];
        label.text = [[InfoTitles objectAtIndex:indexPath.row] objectForKey:@"title"];
    }
    return cell;
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    UITableViewCell * cell = (UITableViewCell*)sender;
    NSIndexPath * indexPath = [self.table indexPathForCell:cell];
    if([self.module intValue]==1){
        InfoTemplate1 * infoTemplate1 = (InfoTemplate1*)segue.destinationViewController;
        infoTemplate1.infoid = [[InfoTitles objectAtIndex:indexPath.row] objectForKey:@"id"];
    }else{
        InfoTemplate2 * infoTemplate2 = (InfoTemplate2*)segue.destinationViewController;
        infoTemplate2.infoid = [[InfoTitles objectAtIndex:indexPath.row] objectForKey:@"id"];
    }
    
    
}

@end
